namespace Beauty.Net.Ocelot.Core;

/// <summary>
/// Ocelot配置选项
/// </summary>
public class OcelotOptions
{
    /// <summary>
    /// 配置文件路径
    /// </summary>
    public string ConfigurationPath { get; set; } = "ocelot.json";
    
    /// <summary>
    /// 是否启用管理API
    /// </summary>
    public bool EnableAdministration { get; set; } = false;
    
    /// <summary>
    /// 管理API路径
    /// </summary>
    public string AdministrationPath { get; set; } = "/administration";
    
    /// <summary>
    /// 管理API密钥
    /// </summary>
    public string AdministrationKey { get; set; } = string.Empty;
    
    /// <summary>
    /// 是否启用Consul服务发现
    /// </summary>
    public bool EnableConsulServiceDiscovery { get; set; } = false;
    
    /// <summary>
    /// Consul配置
    /// </summary>
    public ConsulDiscoveryOptions ConsulDiscovery { get; set; } = new();
    
    /// <summary>
    /// 是否重载配置
    /// </summary>
    public bool ReLoadOnChange { get; set; } = true;
    
    /// <summary>
    /// 重载间隔（秒）
    /// </summary>
    public int ReLoadIntervalSeconds { get; set; } = 180;
}

/// <summary>
/// Consul服务发现配置选项
/// </summary>
public class ConsulDiscoveryOptions
{
    /// <summary>
    /// Consul地址
    /// </summary>
    public string Host { get; set; } = "localhost";
    
    /// <summary>
    /// Consul端口
    /// </summary>
    public int Port { get; set; } = 8500;
    
    /// <summary>
    /// 数据中心
    /// </summary>
    public string Datacenter { get; set; } = string.Empty;
    
    /// <summary>
    /// 令牌
    /// </summary>
    public string Token { get; set; } = string.Empty;
    
    /// <summary>
    /// 命名空间
    /// </summary>
    public string Namespace { get; set; } = string.Empty;
    
    /// <summary>
    /// 是否启用健康检查
    /// </summary>
    public bool EnableHealthCheck { get; set; } = true;
    
    /// <summary>
    /// 轮询间隔（毫秒）
    /// </summary>
    public int PollingInterval { get; set; } = 10000;
}

/// <summary>
/// 路由配置模型
/// </summary>
public class ApiRouteOptions
{
    /// <summary>
    /// 路由键
    /// </summary>
    public string RouteKey { get; set; } = string.Empty;
    
    /// <summary>
    /// 上游路径模板
    /// </summary>
    public string UpstreamPathTemplate { get; set; } = string.Empty;
    
    /// <summary>
    /// 上游HTTP方法
    /// </summary>
    public List<string> UpstreamHttpMethod { get; set; } = new();
    
    /// <summary>
    /// 下游服务名称（用于Consul服务发现）
    /// </summary>
    public string ServiceName { get; set; } = string.Empty;
    
    /// <summary>
    /// 下游路径模板
    /// </summary>
    public string DownstreamPathTemplate { get; set; } = string.Empty;
    
    /// <summary>
    /// 下游协议
    /// </summary>
    public string DownstreamScheme { get; set; } = "http";
    
    /// <summary>
    /// 负载均衡策略
    /// </summary>
    public string LoadBalancerOptions { get; set; } = "RoundRobin";
    
    /// <summary>
    /// 是否启用速率限制
    /// </summary>
    public bool EnableRateLimiting { get; set; } = false;
    
    /// <summary>
    /// 速率限制配置
    /// </summary>
    public RateLimitOptions RateLimitOptions { get; set; } = new();
}

/// <summary>
/// 速率限制配置
/// <summary>
public class RateLimitOptions
{
    /// <summary>
    /// 客户端白名单
    /// </summary>
    public List<string> ClientWhitelist { get; set; } = new();
    
    /// <summary>
    /// 允许的请求数
    /// </summary>
    public int PermitLimit { get; set; } = 100;
    
    /// <summary>
    /// 周期（秒）
    /// </summary>
    public int PeriodSeconds { get; set; } = 60;
    
    /// <summary>
    /// 队列大小
    /// </summary>
    public int QueueLimit { get; set; } = 0;
}